package sx.convert;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 
 */

/**
 * @author Administrator
 *
 */
public class Convert {
	private static double getRate(String curr){
		String sql="select rate from ExchangeRate where currency=?";
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		double ret = 0;
		try {
			pstmt = ConnectSQLServer.getCon().prepareStatement(sql);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			pstmt.setString(1,curr);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			rs=pstmt.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			while(rs.next()){
			ret=rs.getDouble(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ret;
	}
	public static String calc(String dollar,String curr){
		double d=Double.valueOf(dollar);
		Double e=d*getRate(curr);
		return e.toString();
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Gui();
	}
}
